<?php

session_start();

if(!isset($_SESSION['user_id'])) {
	echo '<script>location.href=\'../index.php?page=login\'</script>';
}
/*
if(isset($_POST['SaveToAccount'])) {
 	 $db_host = "dbecs.db.8372329.hostedresource.com";
	 $db_user = "dbecs";
	 $db_password = "a!Ll%nM3wr)k[q";
	 $db_name = "dbecs";	
// $db_host = "localhost";
// $db_user = "root";
// $db_password = "123456";
// $db_name = "dbecs";
	
	$db = mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());
		mysql_select_db($db_name, $db) or die(mysql_error());
	
	$check_sql = "SELECT * FROM composedocument_temp WHERE username='".$_SESSION['user_id']."'";
	$result = mysql_query($check_sql);
	if($result) {
		$result2 = mysql_fetch_array($result);
		$nums = @mysql_num_rows($result2);
	}
	if($nums >= 5) {
		echo "You cannot have over 5 on doing assignment";
		//header('location:index.php?page=assignment_manager&_v=c');
		echo "<script>location.href='index.php?page=assignment_manager&_v=c';</script>";
	} else {
		$dets = $_POST['area1'];
		$s_upload_file = $_POST['s_upload_file'];
		
		if(isset($_SESSION['file1'])) {
			$substr = substr($_SESSION['file1'], 0, 26);
			$nfilename1 = split($substr, $_SESSION['file1']);
			if($nfilename1[1] != $s_upload_file) {
				$nfilename1[1] = "";
			} else {
				$nfilename1[1] = $_SESSION['file1'];
			}
		} else {
			$nfilename1[1] = "";
		}
		$aid = intval($_POST['aid']);
		if($aid !=0) {
			$sql = "update composedocument_temp set comments='".$dets."' ,uploads='".$nfilename1[1]."' WHERE id='".$aid."' AND username='".$_SESSION['user_id']."'";
		} else {
			$sql = "insert into composedocument_temp set comments='".$dets."',username='".$_SESSION['user_id']."',types='compose',uploads='".$nfilename1[1]."'";
		}
		$res = mysql_query($sql);
		if($res) {
			//header('location:index.php?page=assignment_manager&_v=c');
			echo "<script>location.href='../index.php?page=assignment_manager&_v=c';</script>";
		}
	}
} else {
	//echo "<script>location.href='../index.php?page=assignment_manager&view=add_assignment';</script>";
}
*/
require_once "dataAccess.php";
$da = new dataAccess();

// check on doing assignment
//$num_of_doing_assignment = $da->check_on_doing_assignment($_SESSION['user_id']);
/*if($num_of_doing_assignment >= 5) {
	echo "You cannot have over 5 on doing assignment";
	//header('location:index.php?page=assignment_manager&_v=c');
	echo "<script>location.href='index.php?page=assignment_manager&_v=c';</script>";
} else {*/
	$url = $_GET['url'];
	$dets = $da->getDoupleQuoteText($_POST['area1']);
	$s_upload_file1 = $_POST['s_upload_file1'];
	$s_upload_file2 = $_POST['s_upload_file2'];
	$s_upload_file3 = $_POST['s_upload_file3'];
	$s_upload_file4 = $_POST['s_upload_file4'];
	$s_upload_file5 = $_POST['s_upload_file5'];
	$s_upload_file6 = $_POST['s_upload_file6'];
	$s_upload_file7 = $_POST['s_upload_file7'];
	$s_upload_file8 = $_POST['s_upload_file8'];
	$s_upload_file9 = $_POST['s_upload_file9'];
	$s_upload_file10 = $_POST['s_upload_file10'];
	$title = $da->getDoupleQuoteText($_POST["assignment_title"]);
	$assignment_id = $_POST['assignment_id'];
	$tr = intval($_POST['tr_post']);
	//echo $title."--".$assignment_id."--".$tr."--".$dets;
	//exit;
	if($assignment_id == 0) {
		//insert assignment to db
		$da->insertCompose3($title, $dets, $_SESSION['user_id'], $tr);
	} else {
		//update assignment
		$da->updateCompose3($title, $dets, $tr, $assignment_id);
	}
	echo "<script>location.href='../".$url."';</script>";
	//$da->insertComposeTemp2('compose', $title, $dets, $_SESSION['user_id']);
	//$temp_id_compose_for_continue = mysql_insert_id();
	
	/*if($s_upload_file1 != "") {
		// update again to pdfterms for continue doing later
		$da->updatePdfTerms_doing_later($temp_id_compose_for_continue, $s_upload_file1);
	}
	if($s_upload_file2 != "") {
		$da->updatePdfTerms_doing_later($temp_id_compose_for_continue, $s_upload_file2);
	}
	if($s_upload_file3 != "") {
		$da->updatePdfTerms_doing_later($temp_id_compose_for_continue, $s_upload_file3);
	}
	if($s_upload_file4 != "") {
		$da->updatePdfTerms_doing_later($temp_id_compose_for_continue, $s_upload_file4);
	}
	if($s_upload_file5 != "") {
		$da->updatePdfTerms_doing_later($temp_id_compose_for_continue, $s_upload_file5);
	}	
	if($s_upload_file6 != "") {
		$da->updatePdfTerms_doing_later($temp_id_compose_for_continue, $s_upload_file6);
	}
	if($s_upload_file7 != "") {
		$da->updatePdfTerms_doing_later($temp_id_compose_for_continue, $s_upload_file7);
	}
	if($s_upload_file8 != "") {
		$da->updatePdfTerms_doing_later($temp_id_compose_for_continue, $s_upload_file8);
	}
	if($s_upload_file9 != "") {
		$da->updatePdfTerms_doing_later($temp_id_compose_for_continue, $s_upload_file9);
	}
	if($s_upload_file10 != "") {
		$da->updatePdfTerms_doing_later($temp_id_compose_for_continue, $s_upload_file10);
	}
	echo "<script>location.href='../index.php?page=assignment_manager&_v=c';</script>";*/
//}
?>